/**
 * Created by dywu on 2015/9/24.
 */
angular.module('mealplan.service.fileupload', ['ngResource'])

    .service('FileUpload', ['$http', '$q', function ($http, $q) {
        this.uploadFileToUrl = function (file) {
            var fd = new FormData();
            fd.append('file', file);
            var deferred = $q.defer();
            $http({
                method: "POST",
                url: uploadUrl,
                data: fd,
                headers: {'Content-Type': undefined},
                transformRequest: angular.identity
            }).success(function (data, status, headers, config) {
                deferred.resolve(data);
            }).error(function (data, status, headers, config) {
                deferred.reject(data);
            });
            return deferred.promise;
        }
    }]);
;